package org.example.erp.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.erp.domain.Inventory;
import org.example.erp.domain.WmIssueLine;
import org.example.erp.service.impl.WmIssueLineServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
public class WmlssueLineController {
    @Autowired
    private WmIssueLineServiceImpl wmIssueLineService;
    @PostMapping("/WmIssueLine/insert")
    public DataResult Insert(@RequestBody WmIssueLine s) {
        boolean save = wmIssueLineService.save(s);
        if (save) {
            return DataResult.success(save ? "成功" : "失败");
        } else {
            return DataResult.error("新增失败");
        }
    }


    @GetMapping("/WmIssueLine/find")
    public DataResult findWmIssueLine(
            @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            Integer id
            ) {
        Page<WmIssueLine> page = new Page<>(currentPage, pageSize);
        page= wmIssueLineService.selectWmIssueLineById(page, id);
        return DataResult.success(page);
    }

    @PutMapping("/WmIssueLine/update")
    public DataResult processInventory(@RequestBody WmIssueLine wmIssueLine) {
        boolean update = wmIssueLineService.updateById(wmIssueLine);
        if (update) {
            return DataResult.success(update ? "成功" : "失败");
        } else {
            return DataResult.error("更新失败");
        }
    }
    @PutMapping("/WmIssueLine/updateShuliang")
    public DataResult processInventory(@RequestBody Inventory lineId) {
        Integer i = wmIssueLineService.updateWmIssueLineById(lineId);
        if (i==0) {
            return DataResult.error("更新失败");
        }else{
            return DataResult.success("成功");
        }

    }
    @DeleteMapping("/WmIssueLine/delete")
    public DataResult deleteWmIssueLine(@RequestBody Integer lineId) {
        boolean remove = wmIssueLineService.removeById(lineId);
        if (remove) {
            return DataResult.success(remove ? "成功" : "失败");
        } else {
            return DataResult.error("删除失败");
        }
    }
}
